# include <cstdio>
# include <algorithm>
# define MAXN 30023
using namespace std;

int f[MAXN], n, m, t, v;

int main() { 
    scanf("%d %d", &n, &m);
    for(int i = 1; i <= m; i++) { 
        scanf("%d %d", &t, &v);
        for(int j = n; j >= t; j--) { 
            f[j] = max(f[j], f[j - t] + v * t);
        }
    }
    printf("%d\n", f[n]);
}
